// Deprecated: moved to modular APIs
export {}

export interface ArticleListQueryDTO {
  keyword?: string
  categoryId?: number
  tagId?: number
  status?: number
  pageNo?: number
  pageSize?: number
  sortBy?: 'latest' | 'views' | 'likes' | 'comments'
}

export async function fetchArticles(params: ArticleListQueryDTO) {
  const resp = await http.get<ApiResponse<PageResponse<ArticleListItemVO>>>('/articles', { params })
  return resp.data
}

export async function fetchArticleDetail(id: number) {
  const resp = await http.get<ApiResponse<ArticleDetailVO>>(`/articles/${id}`)
  return resp.data
}

export async function likeArticle(id: number) {
  const resp = await http.post<ApiResponse<boolean>>(`/articles/${id}/like`)
  return resp.data
}

export async function fetchComments(articleId: number, tree = false, pageNo?: number, pageSize?: number) {
  const resp = await http.get<ApiResponse<CommentVO[] | PageResponse<CommentTreeVO>>>(`/articles/${articleId}/comments`, {
    params: {
      tree,
      pageNo,
      pageSize
    }
  })
  return resp.data
}

export async function addComment(articleId: number, payload: CreateCommentDTO) {
  const resp = await http.post<ApiResponse<boolean>>(`/articles/${articleId}/comments`, payload)
  return resp.data
}

export async function likeComment(commentId: number) {
  const resp = await http.post<ApiResponse<number>>(`/articles/comments/${commentId}/like`)
  return resp.data
}

export async function fetchCommentLikes(ids: number[]) {
  const resp = await http.get<ApiResponse<Record<number, number>>>(`/articles/comments/likes`, { params: { ids: ids.join(',') } })
  return resp.data
}

export async function fetchCategories() {
  const resp = await http.get<ApiResponse<CategoryVO[]>>('/articles/categories')
  return resp.data
}

export async function fetchTags() {
  const resp = await http.get<ApiResponse<TagVO[]>>('/articles/tags')
  return resp.data
}

export async function fetchRelatedArticles(id: number, limit?: number) {
  const resp = await http.get<ApiResponse<ArticleListItemVO[]>>(`/articles/${id}/related`, { params: { limit } })
  return resp.data
}

export async function fetchHotArticles(limit?: number, categoryId?: number, tagId?: number, sinceDays?: number) {
  const resp = await http.get<ApiResponse<ArticleListItemVO[]>>('/articles/hot', { params: { limit, categoryId, tagId, sinceDays } })
  return resp.data
}

export async function fetchArchives(limit?: number) {
  const resp = await http.get<ApiResponse<ArticleArchiveItemVO[]>>('/articles/archives', { params: { limit } })
  return resp.data
}

export async function pageArchives(pageNo: number, pageSize: number) {
  const resp = await http.get<ApiResponse<PageResponse<ArticleArchiveItemVO>>>('/articles/archives/page', { params: { pageNo, pageSize } })
  return resp.data
}

export async function pageHot(pageNo: number, pageSize: number, categoryId?: number, tagId?: number, sinceDays?: number) {
  const resp = await http.get<ApiResponse<PageResponse<ArticleListItemVO>>>('/articles/hot/page', { params: { pageNo, pageSize, categoryId, tagId, sinceDays } })
  return resp.data
}

export async function fetchRecentArticles(limit?: number) {
  const resp = await http.get<ApiResponse<ArticleListItemVO[]>>('/articles/recent', { params: { limit } })
  return resp.data
}

export interface SaveArticleDTO {
  title: string
  content?: string
  summary?: string
  coverImage?: string
  categoryId?: number
  status?: number
}

export async function createArticle(payload: SaveArticleDTO) {
  const resp = await http.post<ApiResponse<{ id: number }>>('/articles', payload)
  return resp.data
}

export async function updateArticle(id: number, payload: SaveArticleDTO) {
  const resp = await http.put<ApiResponse<boolean>>(`/articles/${id}`, payload)
  return resp.data
}

export async function deleteArticle(id: number) {
  const resp = await http.delete<ApiResponse<boolean>>(`/articles/${id}`)
  return resp.data
}


